#ifndef PCAPWRAPPER_H
#define PCAPWRAPPER_H

#include <pcap.h> /* Pcap */

#include <netinet/in.h>     /* Internet */
#include <netinet/ether.h>  /* Link      Layer */
#include <netinet/ip.h>     /* Network   Layer */
#include <netinet/tcp.h>    /* Transport Layer */
#include <arpa/inet.h>
#include "packetheader.h"
#include <queue>
#include <QThread>

#define LOOP_FOREVER -1

typedef struct interface {
    char *name;
    int datalink_type;
} Interface;

class PcapWrapper : public QThread
{
    Q_OBJECT

    char err[PCAP_ERRBUF_SIZE];
    pcap_t * handler;

    QString interfaceName;
    std::queue<PacketHeader> captured_packets;

    bool started;

public:
    PcapWrapper();
    ~PcapWrapper();

    bool isStarted();

    QString getInterfaceName();
    QList<Interface> getInterfaces();

    std::queue<PacketHeader> & getCapturedPackets();

public:
    /* Thread Functions */
    void run();

public slots:
    void startCapture();
    void stopCapture();
    void setInterfaceName(QString interfaceName);

};

#endif // PCAPWRAPPER_H
